<?php

class Application_Form_Task extends Zend_Form
{
    protected $_users;

    public function init()
    {
        $this->_users = new Application_Model_Users();

        $this->setName('task');
        $this->setMethod('post');

        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('Име на задачата')
             ->setRequired(true)
             ->addFilter('StripTags')
             ->addFilter('StringTrim')
             ->addValidator('NotEmpty');

        $info = new Zend_Form_Element_Textarea('info');
        $info->setLabel('Описание')
             ->addFilter('StripTags')
             ->addFilter('StringTrim')
             ->setAttribs(array('cols' => 60, 'rows' => 4));

        $date_start = new Zend_Form_Element_Text('date_start');
        $date_start->setLabel('Дата на започване');

        $date_end = new Zend_Form_Element_Text('date_end');
        $date_end->setLabel('Дата на завършване');

        $supervisor = new Zend_Form_Element_Select('supervisor');
        $supervisor->setLabel('Отговорник')
                   ->addFilter('Int')
                   ->setMultiOptions($this->_users->getUserListSimple());

        $hours_expected = new Zend_Form_Element_Text('hours_expected');
        $hours_expected->setLabel('Предвидени човеко-часа')
                       ->addFilter('Int');

        $status = new Zend_Form_Element_Select('status');
        $status->setLabel('Статус')
               ->addFilter('Int')
               ->setMultiOptions(Application_Model_Statuses::$statuses);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Запис');

        $this->addElements(array(
            $name, $info, $date_start, $date_end, $supervisor,
            $hours_expected, $status, $submit
        ));

        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table', 'class' => 'form')),
            'Form'
        ));

        $this->setElementDecorators(array(
            'ViewHelper',
            'Errors',
            array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'value')),
            array('Label', array('tag' => 'td')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
        ));

        $submit->setDecorators(array(
            'ViewHelper',
            array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'value')),
            array(array('label' => 'HtmlTag'), array('tag' => 'td', 'class' => 'value', 'placement' => 'prepend')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
        ));
    }


}

